package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.utils.ExcelUtil;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.system.domain.Cost;
import com.ruoyi.system.service.ICostService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 费用名称 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-12-24
 */
@Controller
@RequestMapping("/system/cost")
public class CostController extends BaseController
{
    private String prefix = "system/cost";

	@Autowired
	private ICostService costService;
	
	@RequiresPermissions("system:cost:view")
	@GetMapping()
	public String cost()
	{
	    return prefix + "/cost";
	}
	
	/**
	 * 查询费用名称列表
	 */
	@RequiresPermissions("system:cost:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Cost cost)
	{
		startPage();
        List<Cost> list = costService.selectCostList(cost);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出费用名称列表
	 */
	@RequiresPermissions("system:cost:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Cost cost)
    {
    	List<Cost> list = costService.selectCostList(cost);
        ExcelUtil<Cost> util = new ExcelUtil<Cost>(Cost.class);
        return util.exportExcel(list, "cost");
    }
	
	/**
	 * 新增费用名称
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存费用名称
	 */
	@RequiresPermissions("system:cost:add")
	@Log(title = "费用名称", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Cost cost)
	{		
		return toAjax(costService.insertCost(cost));
	}

	/**
	 * 修改费用名称
	 */
	@GetMapping("/edit/{costId}")
	public String edit(@PathVariable("costId") Integer costId, ModelMap mmap)
	{
		Cost cost = costService.selectCostById(costId);
		mmap.put("cost", cost);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存费用名称
	 */
	@RequiresPermissions("system:cost:edit")
	@Log(title = "费用名称", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Cost cost)
	{		
		return toAjax(costService.updateCost(cost));
	}
	
	/**
	 * 删除费用名称
	 */
	@RequiresPermissions("system:cost:remove")
	@Log(title = "费用名称", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(costService.deleteCostByIds(ids));
	}
	
}
